package demo.DataStrucAndAlgo.SingletonPattern;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/7/30-07-30-9:22
 * @Description：demo.DataStrucAndAlgo.SingletonPattern  双检锁/双重校验锁
 */
/*
双检锁/双重校验锁单例模式
    懒初始化
    多线程安全
 */
public class SingletonDCL {
    private volatile static SingletonDCL singleton;

    private SingletonDCL(){};

    public static SingletonDCL getSingleton(){
        if(singleton == null){
            synchronized (SingletonDCL.class){
                if(singleton == null){
                    singleton = new SingletonDCL();
                }
            }
        }
        return singleton;
    }
}
